<?
class Portal
{
	# Database
	private $DB;
	
	# Session
	private $Status;
	private $Character;
	
	# Config
	private $Server;
	private $Prioritize;
	private $ActiveMinutes = 15;
	private $Limit_NewlyAdded = 5;
	private $Limit_RecentActivity = 8;
	private $Limit_RandomLS = 7;
	private $Limit_Top = 5;
	private $Limit_RecentLSActivity = 3;
	private $Limit_Friends = 3;
	private $Limit_Friends_events = 3;
	
	public function Portal($Database, $Character, $Status)	
	{
		$this->DB = $Database;
		$this->Status = $Status;
		$this->Character = $Character;
		$this->Prioritize = $_GET['s'];
		
		if (!$Status)
			$this->Limit_RecentActivity = 3;
		
		if ($this->Status)
		{
			$UserCharacter = $this->DB->GetData(TBL_CHARACTERS, TBL_CHARACTERS_SERVER, false, TBL_CHARACTERS_CICUID ."='". $this->Character ."'");
			$this->Server = $UserCharacter[3][TBL_CHARACTERS_SERVER];
		}
	}
	
	#--------------------------------------------------------------------------------------
	# Method to get the number of active users online
	public function GetActiveOnlineTotal()
	{
		$ActiveDB = $this->DB->GetData(TBL_ACTIVE_USERS, "*", true, TBL_ACTIVE_USERS_TIMESTAMP ." > '". (time()-(60*$this->ActiveMinutes)) ."'");	
		//Show($ActiveDB);	
		return ($ActiveDB[0]);
	}
	
	# Method to get the number of guests online
	public function GetGuestOnlineTotal()
	{
		$Check = $this->DB->GetData(TBL_ACTIVE_GUESTS, "AUTO", true, TBL_ACTIVE_GUESTS_TIMESTAMP ." > '". (time()-(60*$this->ActiveMinutes)) ."'");
		return $Check[0];	
	}
	
	# Method to show active users
	public function ShowActive()
	{
		$ActiveDB = $this->DB->GetData(TBL_ACTIVE_USERS, "*", true, TBL_ACTIVE_USERS_TIMESTAMP ." > '". (time()-(60*$this->ActiveMinutes)) ."'");	

		if ($ActiveDB[0] == 0)	
			echo '<div class="noonline">No one online!</div>';
		else
		{	
			echo '<table width="100%" border="0" cellspacing="0" cellpadding="3" class="activeusers">';	
						
			foreach($ActiveDB[3] as $Active)
			{
				$Username 	= $Active[TBL_ACTIVE_USERS_USERNAME];
				$Character 	= $this->GetLinkedCharacter($Username, $this->Status);
				
				if (!$Character)
					echo '<td><img src="images/icons/misc/guest.png" /></td>
						  <td colspan="2" style="padding-left:23px;font-size:11px;">
						  <span style="color:#999;"><strong>'. $Username .'</strong> 
						  <span style="font-size:10px;">(No Character)</span></span></td>';
				else
					echo $Character;
			}
			
			echo '</table>';
		}
	}
	
	# Method to get Character by ID
	private function GetLinkedCharacter($Username)
	{
		if (empty($Username))
			return false;
		else
		{
			// Get user data
			$UserData = $this->DB->GetData(TBL_USERS, TBL_USERS_CHARACTER, false, TBL_USERS_USERNAME ."='". $Username ."'");
			
			$Fields = array(TBL_CHARACTERS_CICUID,
							TBL_CHARACTERS_NAME,
							TBL_CHARACTERS_SERVER,
							TBL_CHARACTERS_AVATAR,
							TBL_CHARACTERS_EVENTS,
							TBL_CHARACTERS_LASTUPDATED);
						
			// Get the user that matches the name given
			$Character = $this->DB->GetData(TBL_CHARACTERS, implode(",", $Fields), false, TBL_CHARACTERS_CICUID ."='". $UserData[3][TBL_USERS_CHARACTER] ."'");
			
			if ($Character[0])
			{
				$Character  = $Character[3];
				
				switch ($Character[TBL_CHARACTERS_CICUID])
				{
					default: $usercss = "color_guest"; break;
					case '10142176': $usercss = "color_rep"; break;				
					case '1633645':  $usercss = "color_admin"; break;				
					case '1010200':  $usercss = "color_god"; break;
				}
				
				return '<tr><td width="5%"><img src="'. $Character[TBL_CHARACTERS_AVATAR] .'" class="with-tooltip" style="width:18px;height:18px;vertical-align:bottom;" title="<img src=\''. $Character[TBL_CHARACTERS_AVATAR] .'\' />" /></td>
						<td width="80%"><a href="?'. $Character[TBL_CHARACTERS_CICUID] .'" class="'. $usercss .' with-tooltip" style="display:block;" title="Last Updated: '. str_replace("\"", "\'", TranslateTime($Character[TBL_CHARACTERS_LASTUPDATED])) .'">
						<strong>'. $Character[TBL_CHARACTERS_NAME] .'</strong>
						<span class="server">('. $Character[TBL_CHARACTERS_SERVER] .')</span>
						</a></td>
						<td width="15%" align="right" class="events"><div style="padding-right:5px;" class="with-tooltip" title="Total number of: <strong>XIVPads Timeline Events</strong>">'. $Character[TBL_CHARACTERS_EVENTS] .'</div></td></tr>';
			}
			else
			{
				return false;
			}
		}
	}
	
	#--------------------------------------------------------------------------------------
	# Method to get the recent events
	public function RecentActivity()
	{
		// Get Recent Activity Data
		$data = $this->DB->GetData(TBL_TIMELINE, "*", true, NULL, TBL_TIMELINE_DATES, "DESC", array(0,$this->Limit_RecentActivity));
		//Show($data);
		
		// Loop it out
		foreach ($data[3] as $Timeline)
		{
			// Pick a random event from their list
			$event_array = explode(":", $Timeline[TBL_TIMELINE_LINKS]);	
			$chosen_event = $event_array[mt_rand(0, count($event_array)-1)];
			
			// Get Related Character Infor
			$Character = $this->DB->GetData(TBL_CHARACTERS, "*", false, TBL_CHARACTERS_CICUID ."='". $Timeline[TBL_TIMELINE_CICUID] .="'");
			
			// Get the event from the chosen list
			$Event = $this->DB->GetData(TBL_EVENTS, "*", false, TBL_EVENTS_ID ."='". $chosen_event ."'");
			
			$mugshot = $Character[3][TBL_CHARACTERS_AVATAR];
			
			$avatar = '<span class="with-tooltip" title="<img src=\''. $Character[3][TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Character[3][TBL_CHARACTERS_AVATAR] .'" width="32" height="32" style="margin-right:5px;" /></span>';
				
			$message = $Event[3][TBL_EVENTS_SUBJECT];
			if ($message == "Welcome to FFXIV Lodestone Pads!")
				$message = '<span style="color:#3A9B00;font-size:11px;">'. $Event[3][TBL_EVENTS_SUBJECT] .'</span>';
			
			echo '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-bottom:3px; border-bottom:solid 1px #DEE3EB;padding-bottom:3px;" >
					<tr>
						<td width="5%" rowspan="2">'. $avatar .'</td>
						<td width="60%" valign="top"><a href="?'. $Character[3][TBL_CHARACTERS_CICUID] .'" class="top10_name" style="color:#0064D2;font-size:11px;">'. $Character[3][TBL_CHARACTERS_NAME] .' <span style="font-size:10px;color:#777;">('.  $Character[3][TBL_CHARACTERS_SERVER] .')</span></a></td>
						<td width="35%" align="right" valign="middle" class="top10_server" style="font-size:10px;">'. TranslateTime($Timeline[TBL_TIMELINE_DATES], false) .'</td>
					</tr>
					<tr>
						<td colspan="2" valign="top" style="padding-left:5px;" class="EventIcon">'. iconfix(Learn2Spell(Translate($message))) .'</td>
					</tr>
					</table>';
		}
	}
	
	# Method to display the top characters by xivpads events
	public function TopCharacters()
	{
		$Fields = array(TBL_CHARACTERS_CICUID,
						TBL_CHARACTERS_NAME,
						TBL_CHARACTERS_SERVER,
						TBL_CHARACTERS_AVATAR,
						TBL_CHARACTERS_MUGSHOT,
						TBL_CHARACTERS_EVENTS,
						TBL_CHARACTERS_LASTUPDATED,
						TBL_CHARACTERS_SCORE);
						
		$Fields2 = array(TBL_HISTORY_CICUID,
						 TBL_HISTORY_SERVER,
						 TBL_HISTORY_TOTAL);
		if (!empty($this->Character))
		{			
			$server_data_events 	  = $this->DB->GetData(TBL_CHARACTERS, implode(",", $Fields), true, TBL_CHARACTERS_SERVER ."='". $this->Server ."'", TBL_CHARACTERS_EVENTS, "DESC", array(0,$this->Limit_Top));
			$server_data_achievements = $this->DB->GetData(TBL_HISTORY, implode(",", $Fields2), true, TBL_HISTORY_SERVER ."='". $this->Server ."'", TBL_HISTORY_TOTAL, "DESC", array(0,$this->Limit_Top));
			$server_data_levels 	  = $this->DB->GetData(TBL_CHARACTERS, implode(",", $Fields), true, TBL_CHARACTERS_SERVER ."='". $this->Server ."'", TBL_CHARACTERS_SCORE, "DESC", array(0,$this->Limit_Top));
		}
		
		$global_data_events 	  = $this->DB->GetData(TBL_CHARACTERS,	implode(",", $Fields), true, NULL, TBL_CHARACTERS_EVENTS, "DESC", array(0,$this->Limit_Top));
		$global_data_achievements = $this->DB->GetData(TBL_HISTORY, 	implode(",", $Fields2), true, NULL, TBL_HISTORY_TOTAL, "DESC", array(0,$this->Limit_Top));
		$global_data_levels		  = $this->DB->GetData(TBL_CHARACTERS, 	implode(",", $Fields), true, NULL, TBL_CHARACTERS_SCORE, "DESC", array(0,$this->Limit_Top));
		
		//Show($global_data_achievements);
		
		# Global
		echo '<div class="menu" align="center">
			  	<span style="color:#0020B9;text-decoration:underline;" onclick="SwitchWidgetData(\'#widget_events\');SwitchWidgetViewDataText(\'events_button\');" class="button" id="events_button">Events</span>
				<span id="split"></span> 
				<span style="color:#0D7700;" onclick="SwitchWidgetData(\'#widget_achievements\');SwitchWidgetViewDataText(\'achievements_button\');" class="button" id="achievements_button">Achievements</span>
				<span id="split"></span>
				<span style="color:#DB0000;" onclick="SwitchWidgetData(\'#widget_levels\');SwitchWidgetViewDataText(\'levels_button\');" class="button" id="levels_button">Levels</span>
			  </div>';
		
		# GLOBAL  
		echo '<div id="global">';
			echo '<div id="global">';
			
				# EVENTS
				echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="activeusers" id="widget_events">';
				foreach ($global_data_events[3] as $Character)
				{
					$mugshot = $Character[TBL_CHARACTERS_AVATAR];
					
					$avatar = '<span class="with-tooltip" title="<img src=\''. $Character[TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Character[TBL_CHARACTERS_AVATAR] .'" width="18" height="18" /></span>';
						
					// Set Character Information			
					echo '<tr>
					<td align="left" width="15%"><strong style="font-size:13px">'. $Character[TBL_CHARACTERS_EVENTS] .'</strong></td>
					<td align="center" width="5%">'. $avatar .'</td>
					<td width="60%"><a href="?'. $Character[TBL_CHARACTERS_CICUID] .'" class="top10_name with-tooltip" style="color:#0064D2;display:block;" title="Last Updated: <strong>'. str_replace("\"", "\'", TranslateTime($Character[TBL_CHARACTERS_LASTUPDATED])) .'</strong>">'. $Character[Name] .'</a></td>
					<td align="right" width="20%" class="top10_server">'. $Character[Server] .'</td>
					</tr>';
					
				}
				echo '</table>';
				
				# ACHIEVEMENTS
				echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="activeusers" id="widget_achievements" style="display:none;" >';
				foreach ($global_data_achievements[3] as $Achievements)
				{		
					$Character =  $this->DB->GetData(TBL_CHARACTERS, implode(",", $Fields), false, TBL_CHARACTERS_CICUID ."='". $Achievements[TBL_HISTORY_CICUID] ."'");
					$Character = $Character[3];
					$mugshot = $Character[TBL_CHARACTERS_AVATAR];
					
					$avatar = '<span class="with-tooltip" title="<img src=\''. $Character[TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Character[Avatar] .'" width="18" height="18" /></span>';
						
					// Set Character Information			
					echo '<tr>
					<td align="left" width="15%"><strong style="font-size:13px">'. $Achievements[TBL_HISTORY_TOTAL] .'</strong></td>
					<td align="center" width="5%">'. $avatar .'</td>
					<td width="60%"><a href="?'. $Character[TBL_CHARACTERS_CICUID] .'" class="top10_name with-tooltip" style="color:#0064D2;display:block;" title="Last Updated: <strong>'. str_replace("\"", "\'", TranslateTime($Character[TBL_CHARACTERS_LASTUPDATED])) .'</strong>">'. $Character[Name] .'</a></td>
					<td align="right" width="20%" class="top10_server">'. $Character[Server] .'</td>
					</tr>';
					
				}
				echo '</table>';
				
				# LEVELS
				echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="activeusers" id="widget_levels" style="display:none;">';
				foreach ($global_data_levels[3] as $Character)
				{
					$FieldsStats = array(TBL_STATS_LEVELS, TBL_STATS_EXP);
					$Stats =  $this->DB->GetData(TBL_CHARACTERS, implode(",", $FieldsStats), false, TBL_STATS_CICUID ."='". $Character[TBL_CHARACTERS_CICUID] ."'");
					$Stats = $Stats[3];
					
					$mugshot = $Character[TBL_CHARACTERS_AVATAR];
					
					$avatar = '<span class="with-tooltip" title="<img src=\''. $Character[TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Character[Avatar] .'" width="18" height="18" /></span>';
						
					// Set Character Information			
					echo '<tr>
					<td align="left" width="15%"><strong style="font-size:13px">'. $Character[TBL_CHARACTERS_SCORE] .'</strong></td>
					<td align="center" width="5%">'. $avatar .'</td>
					<td width="60%"><a href="?'. $Character[TBL_CHARACTERS_CICUID] .'" class="top10_name with-tooltip" style="color:#0064D2;display:block;" title="Last Updated: <strong>'. str_replace("\"", "\'", TranslateTime($Character[TBL_CHARACTERS_LASTUPDATED])) .'</strong>">'. $Character[Name] .'</a></td>
					<td align="right" width="20%" class="top10_server">'. $Character[Server] .'</td>
					</tr>';
					
				}
				echo '</table>';
			
			echo '</div>';
		echo '</div>';
		
		if (!empty($this->Character))
		{
			# SERVER
			echo '<div id="server" style="display:none;">';
				echo '<div id="global">';
				
					# EVENTS
					echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="activeusers" id="widget_events2">';
					foreach ($server_data_events[3] as $Character)
					{
						$mugshot = $Character[TBL_CHARACTERS_AVATAR];
						
						$avatar = '<span class="with-tooltip" title="<img src=\''. $Character[TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Character[TBL_CHARACTERS_AVATAR] .'" width="18" height="18" /></span>';
							
						// Set Character Information			
						echo '<tr>
						<td align="left" width="15%"><strong style="font-size:13px">'. $Character[TBL_CHARACTERS_EVENTS] .'</strong></td>
						<td align="center" width="5%">'. $avatar .'</td>
						<td width="60%"><a href="?'. $Character[TBL_CHARACTERS_CICUID] .'" class="top10_name with-tooltip" style="color:#0064D2;display:block;" title="Last Updated: <strong>'. str_replace("\"", "\'", TranslateTime($Character[TBL_CHARACTERS_LASTUPDATED])) .'</strong>">'. $Character[Name] .'</a></td>
						<td align="right" width="20%" class="top10_server">'. $Character[Server] .'</td>
						</tr>';
						
					}
					echo '</table>';
					
					# ACHIEVEMENTS
					echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="activeusers" id="widget_achievements2" style="display:none;" >';
					foreach ($server_data_achievements[3] as $Achievements)
					{		
						$Character =  $this->DB->GetData(TBL_CHARACTERS, implode(",", $Fields), false, TBL_CHARACTERS_CICUID ."='". $Achievements[TBL_HISTORY_CICUID] ."'");
						$Character = $Character[3];
						$mugshot = $Character[TBL_CHARACTERS_AVATAR];
						
						$avatar = '<span class="with-tooltip" title="<img src=\''. $Character[TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Character[Avatar] .'" width="18" height="18" /></span>';
	
							
						// Set Character Information			
						echo '<tr>
						<td align="left" width="15%"><strong style="font-size:13px">'. $Achievements[TBL_HISTORY_TOTAL] .'</strong></td>
						<td align="center" width="5%">'. $avatar .'</td>
						<td width="60%"><a href="?'. $Character[TBL_CHARACTERS_CICUID] .'" class="top10_name with-tooltip" style="color:#0064D2;display:block;" title="Last Updated: <strong>'. str_replace("\"", "\'", TranslateTime($Character[TBL_CHARACTERS_LASTUPDATED])) .'</strong>">'. $Character[Name] .'</a></td>
						<td align="right" width="20%" class="top10_server">'. $Character[Server] .'</td>
						</tr>';
						
					}
					echo '</table>';
					
					# LEVELS
					echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="activeusers" id="widget_levels2" style="display:none;">';
					foreach ($server_data_levels[3] as $Character)
					{
						$FieldsStats = array(TBL_STATS_LEVELS, TBL_STATS_EXP);
						$Stats =  $this->DB->GetData(TBL_CHARACTERS, implode(",", $FieldsStats), false, TBL_STATS_CICUID ."='". $Character[TBL_CHARACTERS_CICUID] ."'");
						$Stats = $Stats[3];
						
						$mugshot = $Character[TBL_CHARACTERS_AVATAR];
						
						$avatar = '<span class="with-tooltip" title="<img src=\''. $Character[TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Character[Avatar] .'" width="18" height="18" /></span>';;
							
						// Set Character Information			
						echo '<tr>
						<td align="left" width="15%"><strong style="font-size:13px">'. $Character[TBL_CHARACTERS_SCORE] .'</strong></td>
						<td align="center" width="5%">'. $avatar .'</td>
						<td width="60%"><a href="?'. $Character[TBL_CHARACTERS_CICUID] .'" class="top10_name with-tooltip" style="color:#0064D2;display:block;" title="Last Updated: <strong>'. str_replace("\"", "\'", TranslateTime($Character[TBL_CHARACTERS_LASTUPDATED])) .'</strong>">'. $Character[Name] .'</a></td>
						<td align="right" width="20%" class="top10_server">'. $Character[Server] .'</td>
						</tr>';
						
					}
					echo '</table>';
				
				echo '</div>';
			echo '</div>';
		}
	}
	
	# Method to get the top 10 linkshells
	public function TopLinkshells()
	{
		$Fields = array(TBL_LINKSHELL_ID,
						TBL_LINKSHELL_NAME,
						TBL_LINKSHELL_EMBLUM,
						TBL_LINKSHELL_TOTALEVENTS,
						TBL_LINKSHELL_SERVER,
						TBL_LINKSHELL_LASTUPDATED);
		
		if (!empty($this->Character))				
			$data1 = $this->DB->GetData(TBL_LINKSHELL, implode(",", $Fields), true, TBL_LINKSHELL_SERVER ."='". $this->Server ."'", TBL_LINKSHELL_TOTALEVENTS, "DESC", array(0,$this->Limit_Top));
		
		$data2 = $this->DB->GetData(TBL_LINKSHELL, implode(",", $Fields), true, NULL, TBL_LINKSHELL_TOTALEVENTS, "DESC", array(0,$this->Limit_Top));
		
		# Global
		echo '<div id="global2">
			  <table width="100%" border="0" cellspacing="0" cellpadding="2" class="activeusers">';
		// Loop it out
		foreach ($data2[3] as $Linkshell)
		{
			$emblum = '<img src="'. $Linkshell[TBL_LINKSHELL_EMBLUM] .'" width="18" height="18" />';
			
			echo '<tr>
			<td align="left" width="10%"><strong style="font-size:13px">'. $Linkshell[TBL_LINKSHELL_TOTALEVENTS] .'</strong></td>
			<td align="center" width="5%">'. $emblum .'</td>
			<td width="65%"><a href="?ls/'. $Linkshell[TBL_LINKSHELL_ID] .'" class="top10_name with-tooltip" style="color:#0064D2;display:block;" title="Last Updated: <strong>'. str_replace("\"", "\'", TranslateTime($Linkshell[TBL_LINKSHELL_LASTUPDATED])) .'">'. $Linkshell[TBL_LINKSHELL_NAME] .'</strong></a></td>
			<td align="right" width="20%" class="top10_server">'. $Linkshell[TBL_LINKSHELL_SERVER] .'</td>
			</tr>';
		}
		echo '</table></div>';
		
		if (!empty($this->Character))
		{
			# Server
			echo '<div id="server2" style="display:none;">
				  <table width="100%" border="0" cellspacing="0" cellpadding="2" class="activeusers">';
			// Loop it out
			foreach ($data1[3] as $Linkshell)
			{
				$emblum = '<img src="'. $Linkshell[TBL_LINKSHELL_EMBLUM] .'" width="18" height="18" />';
				
				echo '<tr>
				<td align="left" width="10%"><strong style="font-size:13px">'. $Linkshell[TBL_LINKSHELL_TOTALEVENTS] .'</strong></td>
				<td align="center" width="5%">'. $emblum .'</td>
				<td width="65%"><a href="?ls/'. $Linkshell[TBL_LINKSHELL_ID] .'" class="top10_name with-tooltip" style="color:#0064D2;display:block;" title="Last Updated: <strong>'. str_replace("\"", "\'", TranslateTime($Linkshell[TBL_LINKSHELL_LASTUPDATED])) .'">'. $Linkshell[TBL_LINKSHELL_NAME] .'</strong></a></td>
				<td align="right" width="20%" class="top10_server">'. $Linkshell[TBL_LINKSHELL_SERVER] .'</td>
				</tr>';
			}
			echo '</table></div>';
		}
	}
	
	#--------------------------------------------------------------------------------------
	# Friend and Linkshell activity
	public function FriendActivity()
	{
		$GetFriends = $this->DB->GetData(TBL_FRIENDS, "*", false, TBL_FRIENDS_CICUID ."='". $this->Character ."'");
		
		$friends = explode(",", $GetFriends[3][TBL_FRIENDS_ARRAY]);
		shuffle($friends);
		$friends = array_slice($friends, 0,  $this->Limit_Friends);
		
		$i = 1;
		foreach($friends as $Friend)
		{
			$GetChar = $this->DB->GetData(TBL_CHARACTERS, "*", false, TBL_CHARACTERS_CICUID ." = '". $Friend ."'");
			$Char = $GetChar[3];
			$GetEvents = $this->DB->GetData(TBL_EVENTS, "*", true, TBL_EVENTS_CICUID ." = '". $Friend ."'", TBL_EVENTS_AUTO, "DESC", array(0,$this->Limit_Friends_events));
			
			$Events = $GetEvents[3];

			$end = NULL;
			if ($i == count($friends))
				$end = 'style="border-bottom:none;"';
			
			echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="recent_ls_activity" '. $end .'>
				<tr>
				<td width="5%" rowspan="2" align="center" valign="top"><a href="?'. $Char[TBL_CHARACTERS_CICUID] .'"><span class="with-tooltip" title="<img src=\''. $Char[TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Char[TBL_CHARACTERS_AVATAR] .'" width="32" height="32" /></span></a></td>
				<td><a href="?'. $Char[TBL_CHARACTERS_CICUID] .'" style="font-size:15px;padding-left:2px;">'. $Char[TBL_CHARACTERS_NAME] .'</a></td>
				</tr>
				<tr>
				<td style="font-size:11px;padding:2px 2px 2px 10px;">';
				
				echo iconfix(Learn2Spell($Events[0][TBL_EVENTS_DETAILS]));
				echo '<div style="height:5px;"></div>';
				echo iconfix(Learn2Spell($Events[1][TBL_EVENTS_DETAILS]));
				echo '<div style="height:5px;"></div>';
				echo iconfix(Learn2Spell($Events[2][TBL_EVENTS_DETAILS]));
				
			echo '</td>
				</tr>
				</table>';
				
			$i++;
			
		}
	}
	
	public function LSActivity()
	{
		$GetLSs = $this->DB->GetData(TBL_LINKSHELL, "*", true, TBL_LINKSHELL_CACHE ." LIKE '%". $this->Character ."%'", TBL_LINKSHELL_AUTO, "ASC", array(0,$this->Limit_RecentLSActivity));
		
		$i = 1;
		foreach($GetLSs[3] as $LS)
		{
			$GetEvent = $this->DB->GetData(TBL_LINKSHELL_EVENTS, "*", true, TBL_LINKSHELL_EVENTS_GCID ." = '". $LS[TBL_LINKSHELL_ID] ."'", TBL_LINKSHELL_EVENTS_AUTO, "DESC", array(0,$this->Limit_Friends_events));
			
			if ($GetEvent[0] == 0)
				$event_message = "No Events";
			else
				$event_message = $GetEvent[3][TBL_LINKSHELL_EVENTS_MESSAGE];
			
			$end = NULL;
			if ($i == $GetLSs[0])
				$end = 'style="border-bottom:none;"';
			
			echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="recent_ls_activity" '. $end .'>
				<tr>
				<td width="5%" rowspan="2" align="center" valign="top"><a href="?ls/'. $LS[TBL_LINKSHELL_ID] .'"><img src="'. $LS[TBL_LINKSHELL_EMBLUM] .'" width="32" height="32" /></a></td>
				<td><a href="?ls/'. $LS[TBL_LINKSHELL_ID] .'" style="font-size:15px;padding-left:2px;">'. $LS[TBL_LINKSHELL_NAME] .'</a></td>
				</tr>
				<tr>
				<td style="font-size:11px;padding:2px 2px 2px 10px;">';
				
				$Events = $GetEvent[3];
				echo iconfix($Events[0][TBL_LINKSHELL_EVENTS_MESSAGE]);
				echo '<div style="height:5px;"></div>';
				echo iconfix($Events[1][TBL_LINKSHELL_EVENTS_MESSAGE]);
				echo '<div style="height:5px;"></div>';
				echo iconfix($Events[2][TBL_LINKSHELL_EVENTS_MESSAGE]);
				
			echo '</td></tr>
				</table>';
			
			echo "\n";
			
			$i++;
		}
	}
	
	public function NewlyAdded()
	{
		$FieldsA = array(TBL_CHARACTERS_CICUID,
						 TBL_CHARACTERS_NAME,
						 TBL_CHARACTERS_SERVER,
						 TBL_CHARACTERS_AVATAR,
						 TBL_CHARACTERS_CICUID);
						 
		$FieldsB = array(TBL_LINKSHELL_ID,
						 TBL_LINKSHELL_NAME,
						 TBL_LINKSHELL_EMBLUM,
						 TBL_LINKSHELL_SERVER);
						 
		$dataA = $this->DB->GetData(TBL_CHARACTERS, implode(",", $FieldsA), true, NULL, TBL_CHARACTERS_ADDED, "DESC", array(0,$this->Limit_NewlyAdded));
		$dataB = $this->DB->GetData(TBL_LINKSHELL, implode(",", $FieldsB), true, NULL, TBL_LINKSHELL_ADDED, "DESC", array(0,$this->Limit_NewlyAdded));
		
		echo '<div class="contents"><table width="100%" border="0" cellspacing="0" cellpadding="2">';
		// Loop it out
		foreach ($dataA[3] as $Character)
		{
			$avatar = '<span class="with-tooltip" title="<img src=\''. $Character[TBL_CHARACTERS_AVATAR] .'\' />"><img src="'. $Character[TBL_CHARACTERS_AVATAR] .'" width="24" height="24" /></span>';
			
			echo '<tr>
			<td align="center" width="10%">'. $avatar .'</td>
			<td width="90%"><a href="?'. $Character[TBL_CHARACTERS_CICUID].'" class="top10_name" style="color:#0064D2;font-size:14px;">'. $Character[TBL_CHARACTERS_NAME] .' <span style="color:#666;">from '. $Character[TBL_CHARACTERS_SERVER] .'</span>!</a></td>
			</tr>';
		}
		echo '</table></div>';
		echo '<div class="contents"><table width="100%" border="0" cellspacing="0" cellpadding="2">';
		// Loop it out
		foreach ($dataB[3] as $Linkshell)
		{
			$emblum = '<img src="'. $Linkshell[TBL_LINKSHELL_EMBLUM] .'" width="24" height="24" />';
			
			echo '<tr>
			<td align="center" width="10%">'. $emblum .'</td>
			<td width="90%"><a href="?ls/'. $Linkshell[TBL_LINKSHELL_ID] .'" class="top10_name" style="color:#0064D2;font-size:14px;">'. $Linkshell[TBL_LINKSHELL_NAME] .' <span style="color:#666;">from '. $Linkshell[TBL_LINKSHELL_SERVER] .'</span>!</a></td>
			</tr>';
		}
		echo '</table></div>';
	}
}
?>